#!/bin/csh 



#######################################################
set line=04
set it=0
set dmig = migkd_coffstk_wa_it${it}.sgy
set veld = velinit_wa_it${it}.sgy
#######################################################

# convert sgy to grd file = 1
set condgrd = 1
if ( $condgrd == 1) then
segyread tape=$dmig endian=0 | surange > tmp.asc
set cminm = `awk '{ if ( $1 == "cdp" )print $2}' < tmp.asc`
set cmaxm = `awk '{if ( $1 == "cdp" ) print $3}' < tmp.asc`
set ntraces = `awk '{if (NR == 1 ) print $1}' < tmp.asc`
set dzm = `awk '{if ( $1 == "dt" ) print $2/1000000}' < tmp.asc`
set dmaxm = `awk '{if ( $1 == "ns" ) print ($2-1)*'$dzm'}' < tmp.asc`
#echo sufile ntraces cmin cmax: $ntraces $cminm $cmaxm
segyread tape=$dmig endian=0 | sushw key=counit a=1 | suchw key1=cdp key2=cdp | segyhdrs format=5 | segywrite tape=tmp.sgy conv=0 endian=0
/usr/bin/segy2grd tmp.sgy -G${line}_migkd_it${it}.grd -I1/$dzm -R$cminm/$cmaxm/0/$dmaxm -V -Sc -M$ntraces 
segyread tape=$veld endian=0 | sushw key=counit a=1 | suchw key1=cdp key2=cdp | segyhdrs format=5 | segywrite tape=tmp.sgy conv=0 endian=0
/usr/bin/segy2grd tmp.sgy -G${line}_veld_it${it}.grd -I1/$dzm -R$cminm/$cmaxm/0/$dmaxm -V -Sc -M$ntraces                
#set cminm = `grdinfo -C $dmig.grd | tail -1 | awk '{ print $2}'`		
#set cmaxm = `grdinfo -C $dmig.grd | tail -1 | awk '{ print $3}'`
#set zmax=40.0
exit		 
endif





